﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Affinity.Flux;
using Affinity.Synthesis;

namespace UserInterface
{
    /// <summary>
    /// Demonstrates an alternate usage of lambda bindings, without the overhead of 
    /// creating an expression tree every time the get accessor is called.
    /// </summary>
    public class DemoAltViewModel : NotifyPropertyChangedBase
    {
        #region Time

        [Inlet(Contracts.Time.CurrentTime, InletFlags.ReceiveOnUIThread)]
        public DateTime CurrentTime
        {
            get { return _currentTime; }
            set
            {
                if (value == _currentTime) return;
                _currentTime = value;
                RaisePropertyChanged("CurrentTime");
            }
        }
        private DateTime _currentTime;

        public string CurrentSecondType
        {
            get { return CurrentSecondTypeBinding.Bind(this, "CurrentSecondType"); }
        }
        private static readonly LambdaBinding<string> CurrentSecondTypeBinding = 
            LambdaBinding.Create<DemoAltViewModel, string>(
                _ => _.CurrentTime.Second % 2 == 0 ? "Current second is even" : "Current second is odd");        
        

        #endregion

    }
}
